﻿using Autofac;
using Autofac.Extensions.DependencyInjection;
using System;

namespace Microsoft.Extensions.DependencyInjection
{
    public static partial class MediatorServiceCollectionExtensions
    {
        private class DefaultUnitOfWorkBuilder : IUnitOfWorkBuilder
        {
            public IServiceCollection Services { get; private set; }
            public ContainerBuilder ContainerBuilder { get; private set; }
            public DefaultUnitOfWorkBuilder(IServiceCollection services, ContainerBuilder containerBuilder)
            {
                Services = services;
                ContainerBuilder = containerBuilder;
            }
            public IServiceProvider Build()
            {
                ContainerBuilder.Populate(Services);

                return new AutofacServiceProvider(ContainerBuilder.Build());
            }
        }
    }
}
